package com.gun3y.samples;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

import com.gun3y.entity.media.Data;
import com.gun3y.entity.media.Movie;
import com.gun3y.entity.visual.TreeNode;

public class MovieGraphSample {

    public static void main(String[] args) throws UnsupportedEncodingException {
	// String graphName = "http://www.gun3y.com/ontology/movie";
	// TripleStore tripleStore = new TripleStore(graphName);
	// tripleStore.clear();

	Movie movie = generateMovie();
	TreeNode tree = TreeNode.createMovieTree(Arrays.asList(movie));

	String str = "%7B%22name%22%3A%22root%22%2C%22children%22%3A%5B%7B%22name%22%3A%22elysium%22%2C%22children%22%3A%5B%7B%22name%22%3A%22actor%22%2C%22children%22%3A%5B%7B%22name%22%3A%22Patricia+Benoit%22%2C%22children%22%3A%5B%7B%22name%22%3A%22http%3A%2F%2Fwww.rottentomatoes.com%2Fm%2Felysium_2013%2F%22%7D%5D%7D%2C%7B%22name%22%3A…5D%7D%2C%7B%22name%22%3A%22url%22%2C%22children%22%3A%5B%5D%7D%5D%7D%5D%7D";
	// System.out.println(tree.toString());
	String encode = URLEncoder.encode(str, "ISO-8859-1");
	System.out.println(encode);
	System.out.println(URLDecoder.decode(str, "ISO-8859-1"));

	// tripleStore.addTriplesAsBulk(TripleHelper.createTriples(movie));
	//
	// System.out.println(tripleStore);

    }

    public static Movie generateMovie() {
	Movie movie = new Movie();
	String from = "imdb";

	movie.setActors(generateData("actor sd ", from));
	movie.setContentRating(generateData("content Rating", from));
	movie.setCreators(generateData("creator", from));
	movie.setDatePublished(generateData("date asd Published", from));
	movie.setDescription(generateData("description", from));
	movie.setDirectors(generateData("director", from));
	movie.setDuration(generateData("duration", from));
	movie.setGenre(generateData("genre", from));
	movie.setImage(generateData("image", from));
	movie.setKeyword(generateData("keyword", from));
	movie.setName("avatar");
	movie.setProductionCompany(generateData("procution", from));
	movie.setProvider(generateData("privider", from));
	movie.setRating(generateData("rating", from));
	movie.setUrl(generateData("url", from));

	return movie;
    }

    public static List<Data> generateData(String prefix, String from) {
	Random r = new Random();
	List<Data> dataList = new ArrayList<Data>();
	int size = 1 + r.nextInt(10);
	for (int i = 0; i < size; i++) {
	    dataList.add(new Data(prefix + r.nextInt(100), from));
	}

	return dataList;
    }
}
